/* ---------------------------------------------------------------------------------------------
 *
 *            Capital Alliance Software Confidential Proprietary
 *            (c) Copyright CAS 201{x}, All Rights Reserved
 *                          www.pekall.com
 *
 * ----------------------------------------------------------------------------------------------
 */

package com.elvis.music.adapter;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.elvis.music.R;
import com.elvis.music.database.SQLHelper;

public class MyPlayListAdapter extends BaseAdapter {

    private Context mContext;

    private Cursor cursor;

    public MyPlayListAdapter(Context context) {
        mContext = context;
        cursor = mContext.getContentResolver().query(SQLHelper.CONTENT_URI_PLAY_LIST, null, null,
                null, null);
    }

    public int getCount() {
        return cursor.getCount();
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    private TextView LineItemDuration;

    private TextView LineItemName;

    public View getView(int position, View convertView, ViewGroup parent) {
        cursor.moveToPosition(position);
        Cursor cur = mContext.getContentResolver().query(SQLHelper.CONTENT_URI_PLAY_LIST_MUSIC_MAP,
                null, "_play_list_id=" + cursor.getInt(0), null, null);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.lineitem, null);
        }
        LineItemDuration = (TextView) convertView.findViewById(R.id.LineItemDuration);
        LineItemName = (TextView) convertView.findViewById(R.id.LineItemName);
        LineItemName.setText(cursor.getString(1));
        LineItemDuration.setText(mContext.getString(R.string.total_) + cur.getCount()
                + mContext.getString(R.string._songs));
        return convertView;
    }

}
